package com.SwaggerTest.Controller;


import com.fasterxml.jackson.databind.JsonNode;
import com.fasterxml.jackson.databind.ObjectMapper;
import com.fasterxml.jackson.databind.util.JSONPObject;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ExampleProperty;
import lombok.Data;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RestController;

import java.io.IOException;

@RestController
@RequestMapping("/StringvsJsonController")
public class StringvsJsonController {



    @RequestMapping(value = "/StringtoCat",method = RequestMethod.POST)
    @ApiOperation(value = "测试接受一个String 前台填写一个Json字符串")
    @ApiImplicitParam(name = "Cat",dataType ="Cat",examples = @io.swagger.annotations.Example(
            value = {@ExampleProperty(
                    value ="{'name':'age'}",mediaType = "application/json"
            )}

    ))
    public Cat StringtoCat(@RequestBody String Cat) {
        ObjectMapper objectMapper = new ObjectMapper();
         Cat jsonNode = null;
        try {
            jsonNode = objectMapper.readValue(Cat,Cat.class);
        } catch (IOException e) {
            e.printStackTrace();
        }

        return jsonNode;

    }

    @Data
    public static class Cat {

        private String name;
        private String age;
    }
}
